home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / symbol.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  178 lines

  1. /*
  2.  * $Id: symbol.h,v 0.91 1994/02/20 00:06:09 zhao Pre-Release $
  3.  *
  4.  *. This file is part of BIT shareware package. After the two weeks of 
  5.  *  free evaluation period, you are encouraged (required) to register 
  6.  *  your copy for a small registration fee, which is $35 for personal use
  7.  *  and $50 for commercial, government and institutional use.
  8.  *  
  9.  *  Copyright(c) 1993, 1994 by T.C. Zhao.
  10.  *  All rights reserved.
  11.  *
  12.  *  Permission to use, copy, and distribute this software in its entirety
  13.  *  for non-commercial purposes is hereby granted, provided that the 
  14.  *  above shareware and copyright notices and this permission notice
  15.  *  appear in all copies and their documentation.
  16.  *
  17.  *  This software may be modified for your own use, but modified versions
  18.  *  may not be distributed without prior consent of the author.
  19.  *
  20.  *  This software is provided "as is" without expressed or implied
  21.  *  warranty of any kind.
  22.  *
  23.  *.
  24.  * Defination for default fonts and symbols. Only need to be
  25.  * included by text.c.
  26.  * This stuff definately should not be hard-coded
  27.  *
  28.  */
  29. #ifndef BIT_SYMBOL_H
  30. #define BIT_SYMBOL_H
  31.  
  32. /*
  33.  * default fonts.
  34.  * font index 0 is the default font, So it is a good idea to set
  35.  * the first one to be a mono-spaced font. Also, symbol font
  36.  * must present in order for font switching to work
  37.  */
  38. static char *fonts[] =
  39. {
  40.     "Courier",
  41.     "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",
  42.     "Helvetica-Oblique", "Helvetica-Bold", "Helvetica",
  43.     "Courier-Bold", "Courier-BoldOblique", "Courier-Oblique",
  44.     "Symbol", "Boston", "Screen", "Screen-Bold",
  45.     "Charter-Black", "Charter-Italic", "Charter-BlackItalic",
  46.     "cursor"
  47. };
  48.  
  49. static totalfont = sizeof(fonts) / sizeof(fonts[0]);
  50. /*
  51.  * Standard PS encoding for symbol font
  52.  */
  53. typedef struct {
  54.     const char *name;
  55.     const char *code;
  56. } SymCode_t;
  57.  
  58. static const SymCode_t msymcode[] =
  59. {
  60.     {"forall", "\42"},
  61.     {"universal", "\42"},
  62.     {"Delta", "D"},
  63.     {"Phi", "G"},
  64.     {"Gamma", "G"},
  65.     {"Lambda", "L"},
  66.     {"Pi", "P"},
  67.     {"Theta", "Q"},
  68.     {"Sigma", "S"},
  69.     {"sum", "S"},
  70.     {"Omega", "W"},
  71.     {"Psi", "Y"},
  72.     {"therefore", "\\"},
  73.     {"perp", "^"},
  74.     {"alpha", "a"},
  75.     {"beta", "b"},
  76.     {"chi", "c"},
  77.     {"delta", "d"},
  78.     {"epsilon", "e"},
  79.     {"phi", "j"},
  80.     {"gamma", "g"},
  81.     {"eta", "h"},
  82.     {"psi", "i"},
  83.     {"kappa", "j"},
  84.     {"lambda", "l"},
  85.     {"mu", "m"},
  86.     {"nu", "n"},
  87.     {"pi", "p"},
  88.     {"theta", "q"},
  89.     {"rho", "r"},
  90.     {"sigma", "s"},
  91.     {"tau", "t"},
  92.     {"omega", "w"},
  93.     {"xi", "x"},
  94.     {"Psi", "y"},
  95.     {"le", "\243"},
  96.     {"lessequal", "\243"},
  97.     {"infty", "\244"},
  98.     {"infinity", "\244"},
  99.     {"club", "\247"},
  100.     {"diamond", "\250"},
  101.     {"heart", "\251"},
  102.     {"spade", "\252"},
  103.     {"uparrow", "\255"},
  104.     {"downarrow", "\257"},
  105.     {"leftarrow", "\254"},
  106.     {"rightarrow", "\256"},
  107.     {"pm", "\262"},
  108.     {"plusmqimus", "\262"},
  109.     {"ge", "\263"},
  110.     {"greatequal", "\263"},
  111.     {"times", "\264"},
  112.     {"multiply", "\264"},
  113.     {"prop", "\265"},
  114.     {"partial", "\266"},
  115.     {"bullet", "\267"},
  116.     {"ne", "\271"},
  117.     {"approx", "\273"},
  118.     {"pluscirc", "\305"},
  119.     {"crosscirc", "\304"},
  120.     {"register", "\322"},
  121.     {"copyright", "\323"},
  122.     {"Leftarrow", "\334"},
  123.     {0, 0}                      /* sentinel */
  124. };
  125.  
  126. /* non-math symbols. ISOLatin1 enconding */
  127. static const SymCode_t symcode[] =
  128. {
  129.     {"AA", "\305"},
  130.     {"aa", "\344"},
  131.     {0, 0}
  132. };
  133.  
  134. #include <string.h>
  135. #include <stdlib.h>
  136.  
  137. /* see is a string is a number */
  138. static const char *
  139. check_number(const char *name)
  140. {
  141.     static char tmpstr[50];
  142.     char  *where;
  143.     int    code;
  144.     code = strtol(name, &where, 8);
  145.     if (where == name || code == 0)
  146.         return name;
  147.     tmpstr[0] = code;
  148.     tmpstr[1] = '\0';
  149.     return strncat(tmpstr, where, sizeof(tmpstr) - 3);
  150. }
  151.  
  152. /* given a math symbol name, returns the code or letter */
  153. static const char *
  154. mathcode(const char *name)
  155. {
  156.     register const SymCode_t *p;
  157.  
  158.     for (p = msymcode; p->name; p++)
  159.         if (p->name[0] == *name && strcmp(name, p->name) == 0)
  160.             return p->code;
  161.     /* not a predefined name, check if a number */
  162.     return check_number(name);
  163. }
  164.  
  165. static const char *
  166. spcode(const char *name)
  167. {
  168.     register const SymCode_t *p;
  169.  
  170.     for (p = symcode; p->name; p++)
  171.         if (p->name[0] == *name && strcmp(name, p->name) == 0)
  172.             return p->code;
  173.     /* not a predefined name, check if a number */
  174.     return check_number(name);
  175. }
  176. #endif
  177.  
  178.